package com.example.controller;

import com.example.common.Result;
import com.example.entity.Address;
import com.example.service.AddressService;
import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Resource
    private AddressService addressService;

    @GetMapping("/selectAll")
    public Result selectAll() {
        List<Address> list = addressService.selectAll();
        return Result.success(list);
    }

    @GetMapping("/selectByUserId/{id}")
    public Result selectByUserId(@PathVariable Integer id) {
        List<Address> list = addressService.selectByUser(id);
        return Result.success(list);
    }

    @PostMapping("/addAddress")
    public Result addAddress(@RequestBody Address address) {
        addressService.AddAddress(address);
        return Result.success();
    }

    @DeleteMapping("/deleteAddressById/{addressId}")
    public Result deleteAddressById(@PathVariable Integer addressId) {
        addressService.deleteAddressById(addressId);
        return Result.success();
    }
}
